﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Jumpton.SFA.Server.BusinessRule.MasterData;
using Jumpton.SFA.Server.Entity;
using Jumpton.Persistent;

public partial class masterdata_Product_Uoms_List : PageBase
{
    Product_UomsManager manager = new Product_UomsManager();
    private int productID = 0;
    private const string REQUEST_PRODUCT_ID = "productID";
    private const string RESPONSE_PRODUCT_DETAIL = "Product_detail.aspx?id=";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString[REQUEST_PRODUCT_ID] != null)
        {
            int.TryParse(Request.QueryString[REQUEST_PRODUCT_ID],out productID);
        }

        if (!IsPostBack)
        {
            GetUomsType();
            GetProductUomsBind();

            //PRODUCT_UOMS product_uoms = manager.Load(_Uoms);
            //if (product_uoms!=null)
            //{
            //    ddlUoms.SelectedValue = product_uoms.UomsCode;
            //    txtNum.Value = product_uoms.DENOMINATOR.ToString() ;
            //    chkYesNo.Checked = product_uoms.VALID == "1" ? true : false;
            //    txtWeight.Value = product_uoms.WEIGHT.ToString();
            //    txtVal.Value = product_uoms.VOLUME.ToString() ;
            //}

        }
    }

    private void InitForm()
    {
        if (productID > 0)
        {
            PRODUCTS product = new ProductManager().Load(productID);
            if (product != null)
            {
                lblProductCode.Text = product.ProductCode;
                lblProductName.Text = product.ProductName;
            }
        }
    }

    #region 绑定基本规格
    public void GetUomsType()
    {
        //ddlUoms.DataSource = UomsManager.GetUoms(MyStateManager.DomainID);
        //ddlUoms.DataTextField = "UomsDescription";
        //ddlUoms.DataValueField = "UomsCode";
        //ddlUoms.DataBind();
        //ddlUoms.Items.Insert(0, new ListItem("-选择规格-", ""));
    }
    #endregion

    public void GetProductUomsBind()
    {
        GridView1.DataSource = manager.GetProductUomsTable(MyStateManager.DomainID, productID);
        GridView1.DataBind();
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        //PRODUCT_UOMS product_uoms = null;


        //product_uoms = manager.Load(_Uoms);

        //if (product_uoms == null)
        //    product_uoms = new PRODUCT_UOMS();

        //product_uoms.UomsCode = ddlUoms.SelectedValue;
        //product_uoms.DENOMINATOR = Decimal.Parse(txtNum.Value);
        //product_uoms.VALID = chkYesNo.Checked ? "1" : "0";
        //product_uoms.DOMAINID = MyStateManager.DomainID;
        //product_uoms.PRODUCTID =Decimal.Parse(_ID.ToString());
        //product_uoms.LAST_UPDATE = MyStateManager.Name;
        //product_uoms.SELLFLAG = chkYesNo.Checked ? "1" : "0";
        //product_uoms.LAST_UPDATE_TIME = DateTime.Now;
        //product_uoms.WEIGHT = (string.IsNullOrEmpty(txtWeight.Value)) ? 0 : Decimal.Parse(txtWeight.Value);
        //product_uoms.VOLUME = (string.IsNullOrEmpty(txtVal.Value)) ? 0 : Decimal.Parse(txtVal.Value);

        //manager.Save(product_uoms);

        //Response.Redirect(string.Format("Product_Uoms_List.aspx?id={0}&ProductName={1}",_ID,_ProductName));
    }

    protected void btnBack_Click(object sender, EventArgs e)
    {
        //Response.Redirect(RESPONSE_PRODUCT_DETAIL+_ID.ToString());
    }
}
